package bai10;

import java.util.Scanner;

public class Employee {
	private int id;
	private String name;
	private String username;
	private String birthOfDate;
	private  String gender;
	private String address;
	private String email;
	private double salary;
	public Employee(){

	}
	public Employee(int id, String name, String username, String birthOfDate,
			String gender, String address, String email, double salary) {
		this.id = id;
		this.name = name;
		this.username = username;
		this.birthOfDate = birthOfDate;
		this.gender = gender;
		this.address = address;
		this.email = email;
		this.salary = salary;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getBirthOfDate() {
		return birthOfDate;
	}
	public void setBirthOfDate(String birthOfDate) {
		this.birthOfDate = birthOfDate;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public double getsalary() {
		return salary;
	}
	public void setsalary(double salary) {
		this.salary = salary;
	}
	class EmailException extends Exception{
		 EmailException(String email) {
			 super(email);
		}	
	}
	class Email2Exception extends Exception{
		Email2Exception(String a){
			super(a);
		}
	}
	class inputEmail{
		void nhap() throws EmailException, Email2Exception{
			EmailValidator validator=new EmailValidator();
			Scanner ip=new Scanner(System.in);
			System.out.println("Enter Email:");
			String email=ip.nextLine();
			while(email.trim().equalsIgnoreCase(""))
			throw new EmailException("Email null"); 
			if(!validator.validate(email)){
				throw new Email2Exception("Email invalid");
			}
		}
	}
	public void inputEmployee() throws EmailException, Email2Exception{
		Scanner ip=new Scanner(System.in);
		System.out.println("Employee Information");
		try{
			System.out.println("Enter Id:");
			id=Integer.parseInt(ip.nextLine());
		}catch(NumberFormatException e){
			System.out.println("Id  invalid");
		}
		System.out.println("Enter Name:");
		name=ip.nextLine();
		while(name.trim().equalsIgnoreCase("")){
			System.out.println("Name null");
			name=ip.nextLine();
		}
		System.out.println("Enter Username: ");
		username=ip.nextLine();
		while(username.trim().equalsIgnoreCase("")){
			System.out.println("Username null.Try again!");
			username=ip.nextLine();
		}
		System.out.println("Enter BirthOfDate: ");
		birthOfDate=ip.nextLine();
		while(birthOfDate.trim().equalsIgnoreCase("")){
			System.out.println("BirthOfdate null.Try again!");
			birthOfDate=ip.nextLine();
		}
		System.out.println("Enter gender:");
		gender=ip.nextLine();
		while(gender.trim().equalsIgnoreCase("")){
			System.out.println("Gender null.Try again!");
			gender=ip.nextLine();
		}
		System.out.println("Enter Address: ");
		address=ip.nextLine();
		while(address.trim().equalsIgnoreCase("")){
			System.out.println("Address null.Try again!");
			address=ip.nextLine();
		}
		try{
			new inputEmail().nhap();
		}catch(EmailException ex){
			System.out.println(ex.getMessage());
		}catch(Email2Exception e){
			System.out.println(e.getMessage());
		}
//		System.out.println("Enter Email: ");
//		email=ip.nextLine();
//		while(email.trim().equalsIgnoreCase("")){
//			System.out.println("Email null.Try again!");
//			email=ip.nextLine();
//		}
		try{
			System.out.println("Enter Salary: ");
			double salary=Double.parseDouble(ip.nextLine());
		}catch(NumberFormatException e){
			System.out.println("Salary invalid");
		}
	}
}

